#include "button.h"
#include "MultiButton.h"

static uint8_t read_key1_pin(void);

KEYClassStruct KEYClass = {
	.Init = KEY_init,
	.Read_key1 = read_key1_pin
};

struct Button key1;
static const char* TAG = "button";

#define KEY1_PIN	GPIO_NUM_21

static void KEY_GPIO_Config(void)
{
    gpio_set_direction(KEY1_PIN, GPIO_MODE_INPUT);
	gpio_set_pull_mode(KEY1_PIN, GPIO_FLOATING);
}

static uint8_t read_key1_pin(void)
{
	return gpio_get_level(KEY1_PIN);
}

static void key1_shortPress_handle(void *btn)
{

	ESP_LOGI(TAG, "key1 short pressed");
}

static void key1_longPress_handle(void *btn)
{

	ESP_LOGI(TAG, "key1 long pressed");
}

static void KEYScan_run_task(void *pvParameter)
{

	while(1)
	{
		button_ticks();
		vTaskDelay(5 / portTICK_PERIOD_MS);
	}
	
}

void KEY_init(void)
{
	KEY_GPIO_Config();
	button_init(&key1, read_key1_pin, 0);
	button_attach(&key1, SINGLE_CLICK, key1_shortPress_handle);
	button_attach(&key1, LONG_PRESS_START, key1_longPress_handle);
	button_start(&key1);

	xTaskCreate(&KEYScan_run_task, "KEYScan_run_task", 2048, NULL, 0, NULL);
}



